#ifndef ADDON_MANAGER_H
#define ADDON_MANAGER_H
#include <qevent.h>
#include "Def.h"
#include "ModuleInfo.h"

/*
class AddonMessage
{
public:
	void setSender(const QString& package,const QString& addon)
	{
		fromPackage = package;
		fromAddon = addon;
	}

	void setReceiver(const QString& package,const QString& addon)
	{
		toPackage = package;
		toAddon = addon;
	}

	void setMessage(const QString& head,const QString& body)
	{
		title = head;
		message = body;
	}

	QString fromPackage,fromAddon;
	QString toPackage,toAddon;
	QString title,message;
};*/

class Addon : public IDeleter
{
public:
	virtual void initial() = 0;

	virtual WidgetFrameLess* createAddonWidget(QWidget* parent) = 0;

	virtual bool process(const QMouseEvent& event) = 0;
	virtual bool process(const QKeyEvent& event) = 0;
	virtual bool process(const QWheelEvent& event) = 0;

	//virtual void receivedMessage(const AddonMessage& message) = 0;
	//virtual void sendMessage(const AddonMessage& message) = 0;

	virtual ModuleInfo getAddonInfo()const = 0;
};

class AddonPackage : public IDeleter
{
public:
	virtual void initial() = 0;
	virtual void registerAddon(Addon* addon) = 0;
	virtual QStringList getAddonNameList()const = 0;
	virtual Addon* getAddonByName(const QString& name)const = 0;

	virtual bool process(const QMouseEvent& event) = 0;
	virtual bool process(const QKeyEvent& event) = 0;
	virtual bool process(const QWheelEvent& event) = 0;

	//virtual void receivedMessage(const AddonMessage& message) = 0;
	//virtual void sendMessage(const AddonMessage& message) = 0;

	virtual ModuleInfo getAddonInfo()const = 0;
};

class AddonManagerPrivate;
class SDK_EXPORT_API AddonManager
{
	DECLARE_PRIVATE(AddonManager)
public:
	static AddonManager* instance();

	virtual void initial();
	virtual void destroy();

	virtual bool addPackageFromFile(const QString& file);
	virtual bool addPackageFromDir(const QString& dir);

	virtual AddonPackage* createPackage(const ModuleInfo& info);
	virtual void addPackage(AddonPackage* package);

	virtual QStringList getPackageNameList()const;
	virtual AddonPackage* getPackageByName(const QString& name);
public:
	//virtual WidgetFrameLess* createAddonWidget()const;

	virtual bool process(const QMouseEvent& event);
	virtual bool process(const QKeyEvent& event);
	virtual bool process(const QWheelEvent& event);

    //virtual void receivedMessage(const AddonMessage& message);
	//virtual void sendMessage(const AddonMessage& message);
private:
	AddonManager();
};

//AddonPackage* createAddonPackage();
typedef AddonPackage*(*CreateAddonPackagePointer)();

#define ADDON_POSTFIX ".addon"

#endif